package com.ddzj.scaffold.vo;

import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author:yangzibo
 * @CreateTime:2024-04-14 13:47
 * @Description:
 * @Version:1.0
 **/
public class SecurityUserDetailsVo implements UserDetails, Serializable {
    private String id;
    private String username;
    private String password;
    private String phone;
    private Boolean enable;
    private List<SecurityRoleVo> roles;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(CollectionUtils.isNotEmpty(roles)){
            List<SimpleGrantedAuthority> authorities = new ArrayList<>(roles.size());
            for (SecurityRoleVo role : roles) {
                authorities.add(new SimpleGrantedAuthority(role.getName()));
            }
            return authorities;
        }
        return Lists.newArrayList(new SimpleGrantedAuthority("bj"),new SimpleGrantedAuthority("bjj"));
    }


    /**
     * 获取
     *
     * @return id
     */
    public String getId() {
        return this.id;
    }

    /**
     * 设置
     *
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * 获取
     *
     * @return username
     */
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }

    /**
     * 设置
     *
     * @param username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * 获取
     *
     * @return password
     */
    public String getPassword() {
        return this.password;
    }

    /**
     * 设置
     *
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * 获取
     *
     * @return phone
     */
    public String getPhone() {
        return this.phone;
    }

    /**
     * 设置
     *
     * @param phone
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * 获取
     *
     * @return enable
     */
    public Boolean getEnable() {
        return this.enable;
    }

    /**
     * 设置
     *
     * @param enable
     */
    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    /**
     * 获取
     *
     * @return roles
     */
    public List<SecurityRoleVo> getRoles() {
        return this.roles;
    }

    /**
     * 设置
     *
     * @param roles
     */
    public void setRoles(List<SecurityRoleVo> roles) {
        this.roles = roles;
    }
}
